/*************************************************************************
 * @file: vertex.cpp
 * @date: 01/04/2012
 * TOPOL v1_0 - (c)copyright 2012 TEC/UFF
 *************************************************************************
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 ************************************************************************/

// includes
//----------
#include "vertex.h"
#include "solid.h"
#include "face.h"// remover
#include "loop.h" // remover
#include "halfedge.h"
#include "ipoint.h"
#include <iostream>




///////////////////////////////////////////////////
///  Constructor and Destructor Implementation  ///
///////////////////////////////////////////////////

//-------------------------------------------------------------------------
Vertex::Vertex()
{

}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
Vertex::Vertex( IPoint* _point, Solid* _s )
: m_vertexno( 0 )
, m_prevv( NULL )
, m_nextv( _s->getVertex() )
, m_vedge( NULL )
, m_coord( _point )
, m_isSelected( false )
{
	Vertex* vertexOfSolid = _s->getVertex();
  if( vertexOfSolid )
  {
    vertexOfSolid->m_prevv = this;
  }
  _s->setVertex( this );
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
Vertex::~Vertex()
{
  Solid* _s = m_vedge->getLoop()->getFace()->getSolid();
  if( this->m_prevv )
    this->m_prevv->m_nextv = this->m_nextv;
  if( this->m_nextv )
    this->m_nextv->m_prevv = this->m_prevv;
  if(this == _s->getVertex())
    _s->setVertex( this->m_nextv );
  if( m_coord != NULL )
  {
    delete m_coord;
    m_coord = NULL;
  }
}
//-------------------------------------------------------------------------



///////////////////////////////////////
///  PUBLIC Methods Implementation  ///
///////////////////////////////////////

//-------------------------------------------------------------------------
size_t 
Vertex::getVertexno()
{
  return m_vertexno;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
Vertex* 
Vertex::getPrevVertex()
{
  return  m_prevv;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
Vertex* 
Vertex::getNextVertex()
{
  return  m_nextv;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
HalfEdge* 
Vertex::getVEdge()
{
  return m_vedge;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
IPoint* 
Vertex::getPoint()
{
  return m_coord;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
bool 
Vertex::isSelected()
{
  return m_isSelected;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void 
Vertex::setVertexno( size_t _v )
{
  m_vertexno = _v;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void 
Vertex::setVedge( HalfEdge* _hed ) 
{
		m_vedge = _hed;
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void 
Vertex::setSelection( bool _select )
{
  m_isSelected = _select;
}
//-------------------------------------------------------------------------
